﻿/**
 * 功能:砍箱子事件

 */
//怪物id
var reactorid = 9202012;
var reactorid2 = 9202012;
//开始副本的所在地图
var startmap = 980032200;
//时间到之后退出的地图
var overmap = 910000000;
//死亡之后退到的地图
var deathmap = 910000000;
//副本时间(单位:分钟)
var time = 5;
//坐标x
var mX = -345;//-428
//坐标y
var mY = 164;
//事件名
var PQname = "CaiBox";


function init() {
    em.setProperty("leader", "true");
    em.setProperty("state", "0");//状态检测
}

function setup(eim, leaderid) {
    em.setProperty("leader", "true");
    em.setProperty("state", "1");
    var eim = em.newInstance(PQname);
    var map = eim.setInstanceMap(startmap);
    map.resetFully();
	eim.schedule("spawnreactor", 500);
    eim.startEventTimer(time * 60 * 1000); //30分钟
    return eim;
}


function spawnreactor (eim){
	var map = eim.getMapInstance(0);
	var reactor = em.getReactor(reactorid);//召唤反应堆
	var reactor2 = em.getReactor(reactorid2);//召唤反应堆
		map.spawnReactorOnGroundBelow(reactor, new java.awt.Point(Math.floor(Math.random() * 500),mY));//设置坐标x y
		map.spawnReactorOnGroundBelow(reactor2, new java.awt.Point(-Math.floor(Math.random() * 450),mY));//设置坐标x y
	if (em.getProperty("state") == "1") {
		eim.schedule("spawnreactor", 10 * 1000);//10秒就召唤一个
	}
}

//玩家进入
function playerEntry(eim, player) {
    var map = eim.getMapInstance(0);
    player.changeMap(map, map.getPortal(0));
}

//角色复活触发事件
function playerRevive(eim, player) {
    player.addHP(50);
    var map = eim.getMapFactoryMap(deathmap);
    player.changeMap(map, map.getPortal(0));
    return true;
}


function scheduledTimeout(eim) {
    eim.disposeIfPlayerBelow(100, overmap);
    em.setProperty("state", "0");
    em.setProperty("leader", "true");
}

function changedMap(eim, player, mapid) {
    if (mapid != startmap) {
        eim.unregisterPlayer(player);
        if (eim.disposeIfPlayerBelow(0, 0)) {
            em.setProperty("state", "0");
            em.setProperty("leader", "true");
        }
    }
}

//角色断开连接触发
function playerDisconnected(eim, player) {
    return 0;
}

//杀死怪物触发事件
function monsterValue(eim, mobId) {
    return 1;
}

//角色退出时触发
function playerExit(eim, player) {
    eim.unregisterPlayer(player);

    if (eim.disposeIfPlayerBelow(0, 0)) {
        em.setProperty("state", "0");
        em.setProperty("leader", "true");
    }
}

function end(eim) {
    if (eim.disposeIfPlayerBelow(100, overmap)) {
        em.setProperty("state", "0");
        em.setProperty("leader", "true");
    }
}

function clearPQ(eim) {
    end(eim);
}
//所有怪物死亡触发
function allMonstersDead(eim) {
    var state = em.getProperty("state");
    if (state.equals("1")) {
        em.setProperty("state", "2");
    } else if (state.equals("2")) {
        em.setProperty("state", "3");
    }
}

//离开队伍触发
function leftParty(eim, player) {}
//解散队伍触发
function disbandParty(eim) {}
//在活动角色死亡触发事件
function playerDead(eim, player) {}
//取消自定义事件
function cancelSchedule() {}
//怪物掉落道具
function monsterDrop(eim, player, mob) {}
//捡东西触发
function pickUpItem(eim, player, itemID) {}




